home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / log / writeLogPageHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.0 KB  |  168 lines

  1. /*
  2.  *   $RCSfile: writeLogPageHeader.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:49 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "latch.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "volume.h"
  57. #include "openlog.h"
  58. #include "trans.h"
  59. #include "logrecs.h"
  60. #include "log_intfuncs.h"
  61. #include "log_extfuncs.h"
  62. #include "bf_extfuncs.h"
  63. #include "util_funcs.h"
  64. #include "thread_globals.h"
  65.  
  66.  
  67.  void
  68. writeLogPageHeader (
  69.  
  70.     OPENLOG            *openLog,
  71.     SHORTPID        tailPid 
  72. )
  73. {
  74.  
  75.     GROUPLINK        *tailLink;
  76.     PAGEHASH        *tailBuffer;
  77.     LOGPAGEHDR        *pageHeader;
  78.     LOGPAGEHDR        *endHeader;
  79.     PID                pid;
  80.  
  81.  
  82.     TRPRINT(TR_LOG, TR_LEVEL_1, ("tailPid:%d", tailPid));
  83.  
  84.     if(openLog->writeSemaphore.holder != Active) {
  85.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  86.     }
  87.  
  88.     /* record that the log has a another dirty page to preflush */
  89.     preflushLog();
  90.  
  91.     /* potentially activate a checkpoint */
  92.     activateCheckpoint(FALSE, FALSE, FALSE);
  93.  
  94.     /*
  95.      *    create the pid
  96.      */
  97.     pid.volid = openLog->volid;
  98.     pid.page  = LOG_PAGE_TO_BLOCK(tailPid, openLog);
  99.  
  100.     /*
  101.      *    read the new page
  102.      */
  103.     if ((tailLink = bf_ReadPage(openLog->writeGroup, &pid,
  104.                                 openLog->page2size, BF_NOREAD)) == NULL)    {
  105.  
  106.         SM_ERROR(TYPE_FATAL, Active->errno);
  107.     }
  108.  
  109.     /*
  110.      *    Unfix the page.  The current page does not have to be fixed as
  111.      *    the semaphore on the log protects the currently active page.  This
  112.      *    is an important assumption that will need to be maintained.
  113.      */
  114. #ifndef JUNK
  115.     /* REMOVE */
  116.     openLog->tailLink    = tailLink;
  117. #endif
  118.     
  119.     bf_UnfixPage(tailLink, BF_DEFAULT, FALSE);
  120.  
  121.     /*
  122.      *    record the pointer
  123.      */
  124.     tailBuffer = tailLink->pageHash;
  125.  
  126.     /*
  127.      *    mark that the buffer is a log buffer
  128.      */
  129.     PSET_PAGE_TYPE(tailBuffer, PAGE_LOG);
  130.  
  131.     /*
  132.      * get a pointer to the header and tailer
  133.      */
  134.     pageHeader = (LOGPAGEHDR *) tailBuffer->bufFrame;
  135.     endHeader = (LOGPAGEHDR *) (((char *) pageHeader) + openLog->lastUsableByte);
  136.  
  137.     /*
  138.      *    zero out the pge
  139.      */
  140.     bzero(tailBuffer->bufFrame, (int) openLog->pageSize);
  141.  
  142.     /*
  143.      *    save the new buffer
  144.      */
  145.     openLog->tailBuffer = tailBuffer;
  146.     openLog->tailLink    = tailLink;
  147.  
  148.     /*
  149.      *    check to make sure the first mark and the force mark are zero
  150.      */
  151.     SM_ASSERT(LEVEL_3, ((tailBuffer->forceMark == 0) && (tailBuffer->firstMark == 0)));
  152.  
  153.     /*
  154.      *    initialize the headers on the page
  155.      */
  156.     pageHeader->magic       = LOGPAGE_MAGIC;
  157.     pageHeader->wrapCount  = openLog->wrapCount;
  158.     pageHeader->lastRecord = NULL_LAST_RECORD;
  159.     pageHeader->pageNumber = tailPid;
  160.     *endHeader = *pageHeader;
  161.  
  162.     /*
  163.      *    dirty the page
  164.      */
  165.     DIRTY_PAGE(tailBuffer);
  166.  
  167. }
  168.